#ifndef __UM_UART_H
#define __UM_UART_H

#include "um.h"
#include "uart.h"
#include "UM_Queue.h"

//#pragma pack(1)
typedef struct
{
	u8             state;
	u16            timeout;
	USART_TypeDef* uart;
}UMUartTypeDef;
//#pragma pack()

typedef void (*UM_UART_RxParseFunc)(u16 rdat);

#define UM_UART_DEF(name,n)       	\
static const u8 name##_RQA_SIZE = n;\
static u16 name##_RQA[n] = {0};     \
static UMUartTypeDef name;
//static USART_TypeDef*  name##_UART;

//#define UM_UART_RQ_EZ_Init(name)   		UM_UART_RQ_Init(name.uart,(u16**)&name##_RQA,name##_RQA_SIZE);

#define UM_UART_EZ_Init(name,bps,data_bits,parity,stop_bits)  \
		UART_EZ_Init(name.uart,bps,data_bits,parity,stop_bits);\
		UM_UART_RQ_Init(name.uart,(u16**)&name##_RQA,name##_RQA_SIZE);

extern void UM_UART_RQ_Init(USART_TypeDef* UARTx, u16 **queue_arr,u8 size);

extern u8   UM_UART_RQ_IsUpdated(USART_TypeDef* UARTx);

extern void UM_UART_RQ_Flush(USART_TypeDef* UARTx);

extern RQRetTypeDef UM_UART_RQ_Pop(USART_TypeDef* UARTx,u16* value);

extern u8 UM_UART_RQ_Exec(UMUartTypeDef *sp,UM_UART_RxParseFunc func,u16 tmo_cnt);

#endif
